<template>
  <div class="pagination-container">
    <el-pagination :background="background" :current-page="query.current" :total="query.total" :page-size="query.limit" :page-sizes="pageSizes" :layout="layout" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>

<script>
import { scrollTo } from "@/components/publicJs/utils/scrollTo";

export default {
  name: "Pagination",
  props: {
    background: {
      type: Boolean,
      default: true
    },
    query: {
      type: Object,
      default: () => {}
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50, 100, 200, 500];
      }
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper"
    },
    autoScroll: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleSizeChange(val) {
      this.query.limit = val;
      // if (this.autoScroll) {
      //   scrollTo(0, 800);
      // }
      this.paginationCallBack();
    },
    handleCurrentChange(val) {
      this.query.current = val;
      this.query.start = (val - 1) * this.query.limit;
      // if (this.autoScroll) {
      //   scrollTo(0, 800);
      // }
      this.paginationCallBack();
    },
    paginationCallBack() {
      this.$emit("paginationCallBack");
    }
  }
};
</script>
<style scoped>
.pagination-container {
  width: 100%;
  height: auto;
  text-align: right;
  margin: 36px 0px;
}
</style>
